package com.ssm.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.sfzy.entity.Announcement;
import com.ssm.sfzy.mapper.AnnouncementMapper;
import com.ssm.sfzy.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AnnouncementServiceImpl
 * @Author xiaoliu
 * @Date 2024年03月30日 17:40
 */
@Service
public class AnnouncementServiceImpl implements AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;
    @Override
    public void add(Announcement entity){

        announcementMapper.insert(entity);
    }

    @Override
    public void edit(Announcement entity) {
        announcementMapper.update(entity);
    }

    @Override
    public void remove(Integer id) {

        announcementMapper.delete(id);
    }

    @Override
    public void removeBatch(Integer[] ids) {
        announcementMapper.deleteBatch(ids);
    }

    @Override
    public List<Announcement> find(Announcement entity) {

        return announcementMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Announcement entity) {

        PageHelper.startPage(pageNum,pageSize);
        List<Announcement> list = announcementMapper.select(entity);
        PageInfo<Announcement> pageInfo = new PageInfo<>(list);
        Map<String,Object> map = new HashMap<>();
        map.put("list",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public Announcement findById(Integer id) {
        return announcementMapper.selectById(id);
    }
}
